package servlet;

import service.UserService;
import service.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "AddressAdd", value = "/address/add")
public class AddressAddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/json; charset=utf-8");
        PrintWriter out = response.getWriter();
        String userId = request.getParameter("u_id");
        String province = request.getParameter("province");
        String city = request.getParameter("city");
        String region = request.getParameter("region");
        String street = request.getParameter("street");
        String detailAddress = request.getParameter("detailed_addr");
        String phoneNum = request.getParameter("phone_number");
        UserService service = new UserServiceImpl();
        try {
            int result = service.addAddress(userId,province,city,region,street,detailAddress,phoneNum);
            if(result!=0){
                out.println("T");
            } else {
                out.println("F");
            }
        } catch (Exception e) {
            e.printStackTrace();
            out.println("E");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
